﻿@model IEnumerable<MvcJE.Core.Inet.KeyDataModel>
@{
    ViewBag.Title = "CreateMOP";
}
<h2>
    Create a MOP for: @ViewBag.MopTitle
</h2>
<div class="content-bucket">
    <fieldset style="font-size: 90%;">
        <legend></legend>
        @using (Ajax.BeginForm("CreateMOP", new { controller = "TemplateMgr", area = "Inet", id = ViewBag.MopId }, new AjaxOptions { UpdateTargetId = "mopOutput" }))
        {
            var ctr = 0;
            if (Model != null)
            {   
            <table>
                <tr>
                    <td>
                        <table>
                            @foreach (var item in Model)
                            {
               
                                <tr>
                                    <td>
                                        <input type="hidden" name="param[@ctr].Id" value="@item.Id" />
                                        <input type="hidden" name="param[@ctr].UserKeyValue" value="@item.UserKeyValue" />
                                        <input type="hidden" name="param[@ctr].CalculatedUserKeyValue" value="@item.CalculatedUserKeyValue"
            />
                                    </td>
                                    <td style="text-align: right; font-weight: bold; font-size: 110%; color: Blue">
                                        @item.UniqueKey
                                    </td>
                                    <td>
                                        @if (item.IsTextArea)
                                        { <textarea name="param[@ctr].InputValue" style="width:300px; height:80px" >@item.InputValue</textarea><br />
                                            <span>String Format:</span> @item.UserValue
                                        }
                                        else
                                        {
                                            <input type="text" name="param[@ctr].InputValue" value="@item.InputValue" />
                                        }
                                    </td>
                                </tr>
                                        ctr++;
                            }
                            <tr>
                                <td>
                                </td>
                                <td>
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="Create MOP" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td style="text-align: right; font-weight: bold; font-size: 110%; color: Green">
                                    <input type="submit" name="submit" value="Save Data Entries" />
                                    Title
                                </td>
                                <td>
                                    <input type="text" name="saveTitle" value="@ViewBag.MopTitle" />
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                    
                    </td>
                </tr>
            </table>  
            }
            else
            {
            <h4>
                Template is empty!</h4>
            <br />
            }
        }
        @if (ViewBag.KeyDataMessage != null)
        {
            <p style="color: Red;">
                @MvcHtmlString.Create(ViewBag.KeyDataMessage)
            </p>
        }
    </fieldset>
</div>
<hr />
<div style="float: right">
    <a href="javascript:void(0)" id="saveButton" title="Save this MOP to a file.">Save To
        file</a> | <a href="javascript:void(0)" class="clickToDialog" data-title="Template" data-source-url="/Inet/MopModule/Display/@ViewBag.MopId" data-width="750" data-heigh="600">
            View Template</a> | @Html.ActionLink("Edit", "FullEdit", new { controller = "TemplateMgr", area = "Inet", id = ViewBag.MopId })
</div>
<div id="postMessage">
</div>
<div id="mopOutput">
</div>
<script type="text/javascript">
//<![CDATA[
    jQuery(document).ready(function () {

        $('#saveButton').live("click", function () {
            var t = $('#mopTitle').text();
            var m = $('#mopOutput').html();
            $.post("/inet/mopexpert/savemop", { title: t, mop: m },
            function (data) {
                $('#postMessage').html(data);
            });
        });

        //==================
        // end of document
    });

//]]>
</script>
